{% extends "base.html" %}
{% load i18n %}
{% block head_title %} {% trans "create technology" %} {% endblock %}

{% block center_area %}

<head>
    <style type="text/css">

        .report {font-size: 85%;
                width:200%;
                margin: 0 auto; 
                
                }
        
        td      {
                text-align:center;

                }
        table{
                border-collapse:collapse;
            }
    </style>
</head>

<div class="report">
<div id="verification"></div>
    <a id='technology_list' class="btn btn-primary active" value="TechnologyList" href="{% url technologies_list %}">{% trans 'technology list' %}</a>
<table class="table table-bordered" cellpadding ="0">
<tr>
    <td colspan='3' >
        <table class="table table-bordered" >
            <tr>
                <td colspan='2' rowspan="2">康春机械</td>
                <td colspan='4' rowspan="2">机械加工工艺过程卡</td>
                <td colspan='2'>产品代号</td>
                <td colspan='2'>图号</td>
                <td colspan='2'>零、部、组(整体)件名称</td>
                <td>工艺文件编号</td>
                <td >发放号</td>
            </tr>

            <tr class="">
                <td colspan='2'><!--<input class="form-control" type="text" id="product_symbol" name="technology_level" />--></td>
                <td colspan='2'><input class="form-control" type="text" id="product_cad_code" name="technology_level" /></td>
                <td colspan='2'><!--<input class="form-control" type="text" id="product_name" name="technology_level" />--></td>
                <td><input class="form-control" type="text" id="file_code" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="publish_code" name="technology_level" /></td>
            </tr>
<!--
            <tr>
                <td>机械加工工艺过程卡</td>
                <td><input class="form-control" type="text" id="page_JJGG1" name="technology_level" /></td>
                <td>页</td>
                <td>工艺附图卡</td>
                <td><input class="form-control" type="text" id="page_GF" name="technology_level" /></td>
                <td>页</td>
                <td colspan ="2">零件、辅助材料明细表</td>
                <td><input class="form-control" type="text" id="page_LFCM" name="technology_level" /></td>
                <td>页</td>
                <td>模线样版清单</td>
                <td><input class="form-control" type="text" id="page_MYQ" name="technology_level" /></td>
                <td>页</td>
                <td>总页数</td>
            </tr>

            <tr>
                <td>机械加工工艺规程</td>
                <td><input class="form-control" type="text" id="page_JJGG2" name="technology_level" /></td>
                <td>页</td>
                <td>工艺状态表</td>
                <td><input class="form-control" type="text" id="page_GZ" name="technology_level" /></td>
                <td>页</td>
                <td colspan ="2">工艺装备明细表</td>
                <td><input class="form-control" type="text" id="page_GZM" name="technology_level" /></td>
                <td>页</td>
                <td>工艺文件(封面)</td>
                <td><input class="form-control" type="text" id="page_GW" name="technology_level" /></td>
                <td>页</td>
                <td><input class="form-control" type="text" id="page_Z" name="technology_level" /></td>
            </tr>
-->
            <tr>
                <td colspan='3' align="center">零件数量</td>
                <td colspan='2' align="center">零件质量</td>
                <td colspan='4' align="center">材料</td>
                <td colspan='5' align="center">毛坯</td>
            </tr>

            <tr>
                <td>每个产品</td>
                <td>备件</td>
                <td>总计</td>
                <td>单件</td>
                <td>全套</td>
                <td>牌号</td>
                <td>标准代号</td>
                <td>硬度</td>
                <td>种类</td>
                <td>剖面尺寸</td>
                <td>长度</td>
                <td>数量</td>
                <td>单件质量kg</td>
                <td>全套质量kg</td>
            </tr>

            <tr>
                <td><input class="form-control" type="text" id="LGSL_MGLJ" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="LGSL_BJ" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="LGSL_ZJ" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="LGZL_DJ" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="LGZL_QT" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_mark" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_standard_code" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_hardness" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_species" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_sectional_dimensions" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_length" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_quantity" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_single_weight_kg" name="technology_level" /></td>
                <td><input class="form-control" type="text" id="workblank_full_weight_kg" name="technology_level" /></td>
            </tr>

        </table>
    </td>
<tr/>
<tr>
    <td>
    <table id="operation_groups" class="table table-bordered">
        <thead>
            <tr>
                <td>工序号</td>
                <td>工种</td>
                <td>工序名称</td>
                <td><a id="add-row" href="javascript:void(0)">添加行</a></td>
            </tr>
        </thead>
        <tbody id="OG_body">
            <tr class="operation_group_field" name="operation_group_level">
                <td class="col-md-1"><input class="form-control" type="text" name="GX_GXH" /></td>
                <td class="col-md-4">
                <select name="GX_GZ" class="form-control">
                {% for job in jobs %}
                    <option value="{{ job.id }}" name="GX_GZ">{{ job }}</option>
                {% endfor %}
                </select>
                </td>
                <td class="col-md-6"><input class="form-control" type="text" name="GX_GXMC" /></td>
                <td class="col-md-1"><a name="del-row" href="javascript:void(0)" style="display: none;">删除行</a></td>
            </tr>
        </tbody>
    </table>
    </td>
<tr/>
<tr>
    <td colspan="3">
    <table class="table table-bordered">
        <tr>
            <td>描图</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>阶段标记</td>
        </tr>

        <tr>
            <td rowspan='2'>描较</td>
            <td rowspan='2'></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>编制</td>
            <td>审核</td>
            <td>标准化</td>
            <td>会签</td>
            <td>批准</td>
            <td></td>
        </tr>

        <tr>
            <td>&nbsp;</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>{{ technology.bianzhi.executor.last_name }}{{ technology.bianzhi.executor.first_name }}</td>
            <td>{{ technology.shenhe.executor.last_name }}{{ technology.shenhe.executor.first_name }}</td>
            <td>{{ technology.biaozhunhua.executor.last_name }}{{ technology.biaozhunhua.executor.first_name }}</td>
            <td>{{ technology.huiqian.executor.last_name }}{{ technology.huiqian.executor.first_name }}</td>
            <td>{{ technology.pizhun.executor.last_name }}{{ technology.pizhun.executor.first_name }}</td>
            <td></td>
        </tr>

        <tr>
            <td></td>
            <td>更改标记</td>
            <td>更改单号</td>
            <td>签名</td>
            <td>日期</td>
            <td>更改标记</td>
            <td>更改单号</td>
            <td>签名</td>
            <td>日期</td>
            <td>{{ technology.bianzhi.date_added.date|date:"Y-m-d" }}</td>
            <td>{{ technology.shenhe.date_added.date|date:"Y-m-d" }}</td>
            <td>{{ technology.biaozhunhua.date_added.date|date:"Y-m-d" }}</td>
            <td>{{ technology.huiqian.date_added.date|date:"Y-m-d" }}</td>
            <td>{{ technology.pizhun.date_added.date|date:"Y-m-d" }}</td>
            <td></td>
        </tr>

    </table>
</td>
</tr>
</table>
    <a id='btn_submit' class="pull-right btn btn-primary active" value="Confirm">{% trans 'Confirm' %}</a>
</div>


<script type="text/javascript">
  $("#add-row").click(function(event) {
    operation_group_field = $(this).parent().parent().parent().parent().find('.operation_group_field').first();
    new_operation_group = operation_group_field.clone(true).appendTo("#OG_body");
    new_operation_group.find("input").val('');
    new_operation_group.find("[name='del-row']")[0].removeAttribute("style");
  });
  $("[name='del-row']").click(function(event) {
    new_operation_group = $(this).parent().parent();
    new_operation_group.remove();
  });

  $("#btn_submit").click(function(event) {
    var technology_value = {};
    $("[name='technology_level']").each(function(){
      technology_value[$(this).attr('id')] = $(this).val();
    });
    var operation_groups_value = new Array();
    $("[name='operation_group_level']").each(function(){
      var operation_group_a = {};
      $(this).find("input,select option:selected").each(function(){
        operation_group_a[$(this).attr('name')] = $(this).val();
      });
      operation_groups_value.push(operation_group_a);
    });
    var technology_value_str = JSON.stringify(technology_value);
    var operation_groups_value_str = JSON.stringify(operation_groups_value);
    // alert(technology_value_str + operation_groups_value_str);

    $.ajax({
      type: "POST",
      url: "{% url ajax_create_technology_verification %}",
      dataType: "jsonp",
      jsonp: "callback",
      jsonpCallback:"yuankong",
      data: {
        technology_value_str:technology_value_str,
        operation_groups_value_str:operation_groups_value_str,
      },
      success: function(data) {
        if(data.result==0){
          $.ajax({
            type: "POST",
            url: "{% url ajax_create_technology %}",
            dataType: "jsonp",
            jsonp: "callback",
            jsonpCallback:"yuankong",
            data: {
              technology_value_str:technology_value_str,
              operation_groups_value_str:operation_groups_value_str,
            },
            success: function(data) {
              if(data.result==0){
                window.location.replace("{% url view_technology 999 %}".replace(999,data.technology_id));
              }else{
                alert(data.msg)
              }
            },
            error: function () {
              alert('fail');
            },
          });
        }else{
          $("#verification").html("<div class='alert alert-danger alert-dismissable'>" + "<button type='button' class='close' data-dismiss='alert'>&times;</button>" + data.msg + "</div>");
        }
      },
      error: function () {
        alert('fail');
      },
    });

  });
</script>

{% endblock %}
